{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# A simple Python program to introduce a linked list \n",
    "  \n",
    "# Node class \n",
    "class Node: \n",
    "  \n",
    "    # Function to initialise the node object \n",
    "    def __init__(self, data): \n",
    "        self.data = data  # Assign data \n",
    "        self.next = None  # Initialize next as null \n",
    "  \n",
    "  \n",
    "# Linked List class contains a Node object \n",
    "class LinkedList: \n",
    "  \n",
    "    # Function to initialize head \n",
    "    def __init__(self): \n",
    "        self.head = None\n",
    "  \n",
    "  \n",
    "# Code execution starts here \n",
    "if __name__=='__main__': \n",
    "  \n",
    "    # Start with the empty list \n",
    "    llist = LinkedList() \n",
    "  \n",
    "    llist.head = Node(1) \n",
    "    second = Node(2) \n",
    "    third = Node(3) \n",
    "  \n",
    "    ''' \n",
    "    Three nodes have been created. \n",
    "    We have references to these three blocks as head, \n",
    "    second and third \n",
    "  \n",
    "    llist.head        second              third \n",
    "         |                |                  | \n",
    "         |                |                  | \n",
    "    +----+------+     +----+------+     +----+------+ \n",
    "    | 1  | None |     | 2  | None |     |  3 | None | \n",
    "    +----+------+     +----+------+     +----+------+ \n",
    "    '''\n",
    "  \n",
    "    llist.head.next = second; # Link first node with second  \n",
    "  \n",
    "    ''' \n",
    "    Now next of first Node refers to second.  So they \n",
    "    both are linked. \n",
    "  \n",
    "    llist.head        second              third \n",
    "         |                |                  | \n",
    "         |                |                  | \n",
    "    +----+------+     +----+------+     +----+------+ \n",
    "    | 1  |  o-------->| 2  | null |     |  3 | null | \n",
    "    +----+------+     +----+------+     +----+------+  \n",
    "    '''\n",
    "  \n",
    "    second.next = third; # Link second node with the third node \n",
    "  \n",
    "    ''' \n",
    "    Now next of second Node refers to third.  So all three \n",
    "    nodes are linked. \n",
    "  \n",
    "    llist.head        second              third \n",
    "         |                |                  | \n",
    "         |                |                  | \n",
    "    +----+------+     +----+------+     +----+------+ \n",
    "    | 1  |  o-------->| 2  |  o-------->|  3 | null | \n",
    "    +----+------+     +----+------+     +----+------+  \n",
    "    '''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
